﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpCart.BusinessObjects
{
    public class AmericanExpress:CreditCard
    {
        #region Constructors
        public AmericanExpress(User Owner)
        {
            Db = new SharpCart.Data.SharpDb();
            DataCard = new SharpCart.Data.UserCreditCard();
            DataCard.User = Db.User.First(U => U.EmailAddress == Owner.EmailAddress);
            DataCard.CreditCardType = Db.CreditCardType.First(CCT => CCT.Type == "American Express");
            IsNew = true;
        }
        public AmericanExpress(int ID)
        {
            Db = new SharpCart.Data.SharpDb();
            DataCard = Db.UserCreditCard.First(CC => CC.ID == ID);
            IsNew = false;
        }
        internal AmericanExpress(Data.SharpDb Db, Data.UserCreditCard DataCard)
        {
            this.Db = Db;
            this.DataCard = DataCard;
            IsNew = false;
        }
        #endregion

        #region Instance Methods
        protected override bool IsValidCardNumber(string CardNumber)
        {
            return (CardNumber.Length == 15 &&
                IsLuhnValid(CardNumber) && 
                (CardNumber.StartsWith("34") || 
                CardNumber.StartsWith("37")));
        }
        #endregion

    }
}
